package com.tigerhhzz.springcloud.service.impl;


import com.tigerhhzz.springcloud.dao.AccountDao;
import com.tigerhhzz.springcloud.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.omg.CORBA.TIMEOUT;
import org.springframework.stereotype.Service;
import sun.nio.ch.DefaultSelectorProvider;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

@Service
@Slf4j
public class AccountServiceImpl implements AccountService {

    @Resource
    private AccountDao accountDao;

    @Override
    public void decrease(Long userId, BigDecimal money) {
        log.info("账户扣除余额开始---");

        //模拟超时异常，全局事务回滚
        try {
            TimeUnit.SECONDS.sleep(20);
        }catch (InterruptedException e){
            e.printStackTrace();
        }


        accountDao.decrease(userId, money);
        log.info("账户扣除余额结束---");
    }
}
